import Cookies from 'js-cookie'

const TokenKey = 'ahxmgk-manage-user' + process.env.VUE_APP_Q
const RedbagKey = 'ahxmgk-redbag-user' + process.env.VUE_APP_Q

export function getUser() {
  let app = Cookies.get(TokenKey)
  if(process.env.VUE_APP_DEBUG) {
    app = process.env.VUE_APP_USER
  }
  console.log(app)
  if(app)return JSON.parse(app)
  return {}
}

export function setUser(token) {
  return Cookies.set(TokenKey, JSON.stringify(token))
}

export function removeUser() {
  return Cookies.remove(TokenKey)
}

export function getRedbagUser() {
  let app = Cookies.get(RedbagKey)
  if(process.env.VUE_APP_DEBUG) {
    app = process.env.VUE_APP_R_USER
  }
  if(app)return JSON.parse(app)
  return {}
}

export function setRedbagUser(token) {
  return Cookies.set(RedbagKey, JSON.stringify(token))
}

export function removeRedbagUser() {
  return Cookies.remove(RedbagKey)
}

